<?php
namespace Home\Controller;
use Home\Common\Common;
class RecruitinfoController extends Common {

    /**
     * 分页查询数据
     */
    public function index(){
        $recruitinfo=M('recruitinfo');//实例化为模型
        if(!empty($_POST['tj'])){
            $where= 'state=1 and `rct_title` like "%'.$_POST['tj'].'%"';//得到条件
        }else{
            $where='state=1';
        }
        $count=$recruitinfo->where($where)->count();//总条数
        $page=new \Think\Page($count,8);//实例化分类页
        $show=$page->show();//输出分页
        $list=$recruitinfo->where($where)->limit($page->firstRow.','.$page->listRows)->select();//取出当前页数据

        $admin=M('staffinfo');
        $listid=$admin->select();//查询
        $this->assign('listid',$listid);//输出发布人表

        $this->assign('count',$count);//将总条数输出到页面
        $this->assign('show',$show);//将分页输出到页面
        $this->assign('list',$list);//将数据输出到页面
        $this->display();
    }

    /**
     * 回收站
     */
    public function Recycle_bin(){
        $recruitinfo=M('recruitinfo');//实例化为模型
        if(!empty($_POST['tj'])){
            $where= 'state=0 and `rct_title` like "%'.$_POST['tj'].'%"';//得到条件
        }else{
            $where='state=0';
        }
        $count=$recruitinfo->where($where)->count();//总条数
        $page=new \Think\Page($count,8);//实例化分类页
        $show=$page->show();//输出分页
        $list=$recruitinfo->where($where)->limit($page->firstRow.','.$page->listRows)->select();//取出当前页数据

        $admin=M('staffinfo');
        $listid=$admin->select();//查询
        $this->assign('listid',$listid);//输出发布人表

        $this->assign('count',$count);//将总条数输出到页面
        $this->assign('show',$show);//将分页输出到页面
        $this->assign('list',$list);//将数据输出到页面
        $this->display();
    }
    /**
     * 恢复数据
     */
    public function Recycle_add(){
        if(empty($_POST['id'])){
            $this->error('参数错误!');
        }
        $recruitinfo=M('recruitinfo');
        foreach ($_POST['id'] as $value){
            $recruitinfo->where('rct_id='.$value)->save(array('state'=>1));
        }
        $this->success('恢复成功！',U('Recycle_bin'));
    }
    /**
     * 添加数据
     */
    public function add(){
        if(empty($_POST['submit'])){
            $this->display();
        }else{
            if(empty($_POST['rct_title'])||empty($_POST['rct_starttime'])||empty($_POST['rct_content'])){
                $this->error('请完善数据！');
            }
            if(strtotime($_POST['rct_endtime'])<strtotime($_POST['rct_starttime'])){
                $this->error('截止时间录入有误，请重新录入');
            }
            $recruitinfo=M('recruitinfo');
            $_POST['pubmen']=$_SESSION['aid'];
            $_POST['state']=1;
            $recruitinfo->add($_POST);
            $this->success('添加成功！',U('index'));
        }
    }

    /**
     * 修改数据 or 显示详细数据
     */
    public function upd(){
        if(empty($_POST['submit'])){
            $recruitinfo=M('recruitinfo');
            $info=$recruitinfo->where('rct_id='.$_GET['id'])->find();
            $this->assign('info',$info);
            if(empty($_GET['page'])){
                $this->display();
            }else{
                $admin=M('staffinfo');
                $listid=$admin->select();
                $this->assign('listid',$listid);//输出发布人表
                $this->display('info');
            }

        }else{
            $recruitinfo=M('recruitinfo');
            $recruitinfo->where('rct_id='.$_POST['rct_id'])->save($_POST);
            $this->success('修改成功！',U('index'));
        }
    }

    /**
     * 删除单条数据 (不可删除，设隐藏)
     */
    public function del(){
        if(empty($_GET['id'])){
            $this->error('参数错误！');
        }
        $recruitinfo=M('recruitinfo');
        $recruitinfo->where('rct_id='.$_GET['id'])->save(array('state'=>0));
        $this->success('删除成功！',U('index'));
    }

    /**
     *删除全部 （隐藏）
     */
    public function del_all(){
        if(empty($_POST['id'])){
            $this->error('参数错误');
        }
        $recruitinfo=M('recruitinfo');
        foreach ($_POST['id'] as $value){
            $recruitinfo->where('rct_id='.$value)->save(array('state'=>0));
        }
        $this->success('删除成功！',U('index'));
    }
}